<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author ThinkGem
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <!-- <a-button type="primary" @click="handleForm({})" v-auth="'test:testData:edit'">
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button> -->
      </template>
      <!-- <template #firstColumn="{ record }">
        <a @click="handleForm({ id: record.id })">
          {{ record.testInput }}
        </a>
      </template> -->
    </BasicTable>
  </div>
</template>
<script lang="ts" setup name="ViewsTestTestDataList">
  import { unref } from 'vue';
  import { useEmitter } from '/@/store/modules/user';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { machineTaskListData } from '/@/api/m8/machine/machine';
  import { useDrawer } from '/@/components/Drawer';
  import { useModal } from '/@/components/Modal';
  import { FormProps } from '/@/components/Form';

  const emitter = useEmitter();

  const { t } = useI18n('machine.machine');
  const { meta } = unref(router.currentRoute);
  const { showMessage } = useMessage();

  const getTitle = {
    icon: meta.icon || 'ant-design:book-outlined',
    value: meta.title || t('机床任务日志'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('扫一扫'),
        field: 'picBarCode',
        component: 'Input',
      },
      {
        label: t('图名'),
        field: 'orderPic.picname',
        component: 'Input',
      },
      {
        label: t('图号'),
        field: 'orderPic.picno',
        component: 'Input',
      },
      {
        label: t('机床'),
        field: 'machineId',
        component: 'Input',
      },

      {
        label: t('工序'),
        field: 'oper.operName',
        component: 'Input',
      },
      {
        label: t('负责人'),
        field: 'manNames',
        component: 'Input',
      },
      {
        label: t('日志类型'),
        field: 'logType',
        component: 'Select',
        componentProps: {
          dictType: 'm8_task_log_type',
          allowClear: true,
        },
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('图名'),
      dataIndex: 'orderPic.picname',
      width: 150,
      align: 'left',
    },
    {
      title: t('图号'),
      dataIndex: 'orderPic.picno',
      width: 110,
      align: 'left',
    },
    {
      title: t('工序'),
      dataIndex: 'oper.operName',
      key: 'a.oper_code',
      sorter: true,
      width: 100,
      align: 'left',
    },
    {
      title: t('机床'),
      dataIndex: 'machineId',
      key: 'a.machine_id',
      sorter: true,
      width: 80,
      align: 'center',
    },
    {
      title: t('开始时间'),
      dataIndex: 'beginTime',
      key: 'a.begin_time',
      sorter: true,
      width: 150,
      align: 'center',
    },
    {
      title: t('结束时间'),
      dataIndex: 'endTime',
      key: 'a.end_time',
      sorter: true,
      width: 150,
      align: 'center',
    },
    {
      title: t('任务数'),
      dataIndex: 'task.iqty',
      key: 'task.iqty',
      sorter: true,
      width: 80,
      align: 'center',
    },
    {
      title: t('完工数'),
      dataIndex: 'iqty',
      key: 'a.iqty',
      sorter: true,
      width: 80,
      align: 'center',
    },
    {
      title: t('追加数量'),
      dataIndex: 'moreQty',
      key: 'a.more_qty',
      sorter: true,
      width: 90,
      align: 'center',
    },

    {
      title: t('调试-标准'),
      dataIndex: 'useTsBz',
      key: 'a.use_ts_bz',
      sorter: true,
      width: 100,
      align: 'center',
    },
    {
      title: t('调试-实际'),
      dataIndex: 'useTs',
      key: 'a.use_ts',
      sorter: true,
      width: 100,
      align: 'center',
    },
    {
      title: t('加工-标准'),
      dataIndex: 'useJgBz',
      key: 'a.use_jg_bz',
      sorter: true,
      width: 100,
      align: 'center',
    },
    {
      title: t('加工-实际'),
      dataIndex: 'useJg',
      key: 'a.use_jg',
      sorter: true,
      width: 100,
      align: 'center',
    },
    {
      title: t('加工总长'),
      dataIndex: 'pastOver',
      key: 'a.past_over',
      sorter: true,
      width: 100,
      align: 'left',
    },
    {
      title: t('负责人'),
      dataIndex: 'manNames',
      key: 'a.man_names',
      sorter: true,
      width: 90,
      align: 'center',
    },
    {
      title: t('加工说明'),
      dataIndex: 'remarks',
      key: 'a.remarks',
      sorter: false,
      width: 130,
      align: 'center',
    },
    {
      title: t('任务编号'),
      dataIndex: 'taskCode',
      key: 'a.task_code',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('日志类型'),
      dataIndex: 'logType',
      key: 'a.log_type',
      sorter: true,
      width: 100,
      align: 'left',
      dictType: 'm8_task_log_type',
      fixed: 'right',
    },
  ];

  const [registerTable, { reload /*, getForm*/ }] = useTable({
    api: machineTaskListData,
    beforeFetch: (params) => {
      // 查询前增加默认条件（例子）
      // params.testDate_gte = '2022-05-31';
      // getForm().setFieldsValue(params);
      return params;
    },
    columns: tableColumns,
    // actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleSuccess() {
    reload();
  }
</script>
